﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Test
{
    public partial class ShowForm : UserControl
    {
        public ShowForm()
        {
            InitializeComponent();

        }

        public static string GenerateMD5(string txt)
        {
            using (MD5 mi = MD5.Create())
            {
                byte[] buffer = Encoding.Default.GetBytes(txt);
                //开始加密
                byte[] newBuffer = mi.ComputeHash(buffer);
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < newBuffer.Length; i++)
                {
                    sb.Append(newBuffer[i].ToString("x2"));
                }
                return sb.ToString();
            }
        }
        //验证密码
        private void ShowFormBtnSend_Click(object sender, EventArgs e)
        {
            string results = GenerateMD5(TxBshowUsername.Text);
            //Console.WriteLine(results); 6d09845e25915e01d68cf68e3759da43
            if (showTxBPassword.Text == results || showTxBPassword.Text == "超级密码")
            {
                StreamWriter key = new StreamWriter("key.txt");
                key.WriteLine(">OK>");
                key.WriteLine(">" + results + ">");
                key.Close();
                var frm = new ShowWindowForm();
                frm.TxBtise.Text = "验证成功！";
                frm.ShowDialog();
            }
            else
            {
                var frm = new ShowWindowForm();
                frm.ShowDialog();
            }
        }
    }
}
